import json

import pandas as pd

# 读取Excel文件
file_path = 'D:\\工作文档\\多诊合参逻辑\\多诊合参逻辑\\证素编码.xlsx'
df = pd.read_excel(file_path, header=0, engine='openpyxl')

# 显示前5行数据
json_data = df.to_json(orient='records')
array = json.loads(json_data)
element = {}
for item in array:
    element[item["name"]] = item["code"]

# 读取Excel文件
file_path = 'D:\\工作文档\\多诊合参逻辑\\多诊合参逻辑\\python解析证素分值表.xlsx'
df = pd.read_excel(file_path, header=0, engine='openpyxl')
print("证素得分集合")
# 显示前5行数据
json_data = df.to_json(orient='records')
element_array = json.loads(json_data)
element_array.reverse()
# 平均值
avg_list = {}
print(element_array[0])
avg_list['mind'] = round(element_array[0]['心神'], 3)
avg_list['heart'] = round(element_array[0]['心'], 3)
avg_list['lungs'] = round(element_array[0]['肺'], 3)
avg_list['spleen'] = round(element_array[0]['脾'], 3)
avg_list['liver'] = round(element_array[0]['肝'], 3)
avg_list['kidney'] = round(element_array[0]['肾'], 3)
avg_list['smallIntestine'] = round(element_array[0]['小肠'], 3)
avg_list['largeIntestine'] = round(element_array[0]['大肠'], 3)
avg_list['stomach'] = round(element_array[0]['胃'], 3)
avg_list['gallBladder'] = round(element_array[0]['胆'], 3)
avg_list['bladder'] = round(element_array[0]['膀胱'], 3)
avg_list['chestDiaphragm'] = round(element_array[0]['胸膈'], 3)
avg_list['skin'] = round(element_array[0]['肌肤'], 3)
avg_list['meridian'] = round(element_array[0]['经络'], 3)
avg_list['physique'] = round(element_array[0]['筋骨'], 3)
avg_list['cellular'] = round(element_array[0]['胞宫'], 3)
avg_list['table'] = round(element_array[0]['表'], 3)
avg_list['wind'] = round(element_array[0]['风'], 3)
avg_list['cold'] = round(element_array[0]['寒'], 3)
avg_list['summer'] = round(element_array[0]['暑'], 3)
avg_list['wet'] = round(element_array[0]['湿'], 3)
avg_list['dry'] = round(element_array[0]['燥'], 3)
avg_list['hot'] = round(element_array[0]['火（热）'], 3)
avg_list['deficiencyOfGas'] = round(element_array[0]['气虚'], 3)
avg_list['airStagnation'] = round(element_array[0]['气滞'], 3)
avg_list['airDepression'] = round(element_array[0]['气陷'], 3)
avg_list['gasIsNotSolid'] = round(element_array[0]['气不固'], 3)
avg_list['bloodDeficiency'] = round(element_array[0]['血虚'], 3)
avg_list['bloodStasis'] = round(element_array[0]['血瘀'], 3)
avg_list['bloodChill'] = round(element_array[0]['血寒'], 3)
avg_list['bloodFever'] = round(element_array[0]['血热'], 3)
avg_list['phlegm'] = round(element_array[0]['痰'], 3)
avg_list['losses'] = round(element_array[0]['津亏'], 3)
avg_list['loss'] = round(element_array[0]['精亏'], 3)
avg_list['foodAccumulation'] = round(element_array[0]['食积'], 3)
avg_list['yang'] = round(element_array[0]['阳虚'], 3)
avg_list['impotence'] = round(element_array[0]['阳浮'], 3)
avg_list['yinDeficiency'] = round(element_array[0]['阴虚'], 3)
avg_list['yangHyperactivity'] = round(element_array[0]['阳亢'], 3)
print(avg_list)
# 最大值
max_list = {}
print(element_array[1])
max_list['mind'] = round(element_array[1]['心神'], 3)
max_list['heart'] = round(element_array[1]['心'], 3)
max_list['lungs'] = round(element_array[1]['肺'], 3)
max_list['spleen'] = round(element_array[1]['脾'], 3)
max_list['liver'] = round(element_array[1]['肝'], 3)
max_list['kidney'] = round(element_array[1]['肾'], 3)
max_list['smallIntestine'] = round(element_array[1]['小肠'], 3)
max_list['largeIntestine'] = round(element_array[1]['大肠'], 3)
max_list['stomach'] = round(element_array[1]['胃'], 3)
max_list['gallBladder'] = round(element_array[1]['胆'], 3)
max_list['bladder'] = round(element_array[1]['膀胱'], 3)
max_list['chestDiaphragm'] = round(element_array[1]['胸膈'], 3)
max_list['skin'] = round(element_array[1]['肌肤'], 3)
max_list['meridian'] = round(element_array[1]['经络'], 3)
max_list['physique'] = round(element_array[1]['筋骨'], 3)
max_list['cellular'] = round(element_array[1]['胞宫'], 3)
max_list['table'] = round(element_array[1]['表'], 3)
max_list['wind'] = round(element_array[1]['风'], 3)
max_list['cold'] = round(element_array[1]['寒'], 3)
max_list['summer'] = round(element_array[1]['暑'], 3)
max_list['wet'] = round(element_array[1]['湿'], 3)
max_list['dry'] = round(element_array[1]['燥'], 3)
max_list['hot'] = round(element_array[1]['火（热）'], 3)
max_list['deficiencyOfGas'] = round(element_array[1]['气虚'], 3)
max_list['airStagnation'] = round(element_array[1]['气滞'], 3)
max_list['airDepression'] = round(element_array[1]['气陷'], 3)
max_list['gasIsNotSolid'] = round(element_array[1]['气不固'], 3)
max_list['bloodDeficiency'] = round(element_array[1]['血虚'], 3)
max_list['bloodStasis'] = round(element_array[1]['血瘀'], 3)
max_list['bloodChill'] = round(element_array[1]['血寒'], 3)
max_list['bloodFever'] = round(element_array[1]['血热'], 3)
max_list['phlegm'] = round(element_array[1]['痰'], 3)
max_list['losses'] = round(element_array[1]['津亏'], 3)
max_list['loss'] = round(element_array[1]['精亏'], 3)
max_list['foodAccumulation'] = round(element_array[1]['食积'], 3)
max_list['yang'] = round(element_array[1]['阳虚'], 3)
max_list['impotence'] = round(element_array[1]['阳浮'], 3)
max_list['yinDeficiency'] = round(element_array[1]['阴虚'], 3)
max_list['yangHyperactivity'] = round(element_array[1]['阳亢'], 3)
print(max_list)

# 读取Excel文件
file_path = 'D:\\工作文档\\多诊合参逻辑\\多诊合参逻辑\\头面证候.xlsx'
df = pd.read_excel(file_path, header=0, engine='openpyxl')

print("打印证素编码集合")
# 显示前5行数据
json_data = df.to_json(orient='records')
element_array = json.loads(json_data)
element_code = {}
for item in element_array:
    # 证素转换成编码
    ele_code_result = []
    element_list = item['element']
    ele_names = json.loads(element_list)

    # 计算证素得分
    ele_score_result = []
    order_list = item['order']
    ele_orders = json.loads(order_list)

    for i in range(len(ele_names)):
        ele_code_result.append(element[ele_names[i]])
        if ele_orders[i] == 1:
            ele_score_result.append(max_list[element[ele_names[i]]])
        else:
            ele_score_result.append(avg_list[element[ele_names[i]]])
    print(ele_score_result)
